#include<bits/stdc++.h>
#define lowbit(x) ((x)&-(x))
using namespace std;
int n,m;
pair<long long,long long>  t[500011];
bool cmp(pair<long long,long long> x,pair<long long,long long> y)
{
	return x.first * y.second > y.first * x.second;
}
void add(int p,pair<long long,long long> x)
{
	while(p)
		t[p] = (cmp(x,t[p]) ? x : t[p]),p -= lowbit(p);
}
pair<long long,long long> ask(int p)
{
	pair<long long,long long> res = {0,1};
	while(p <= n)
		res = (cmp(t[p],res) ? t[p] : res),p += lowbit(p);
	return res;
}
int a[500011],s[500011];
int mx[500011],mn[500011],top1,top2;
vector<pair<int,pair<long long,long long> > > v[500011];
pair<long long,long long> niu_niu[500011];
long long SQR(long long x)
{
	return x * x;
}
pair<long long,long long> QR(int i,int j)//i > j
{
	return {SQR(s[i] - s[j]),(i - j)};
}
int kk[500011];
void Solve()
{
	pair<long long,long long> res = {0,1};
	int l,r;
	cin >> l >> r;
	mx[top1 = 1] = mn[top2 = 1] = l - 1;
	for(int i = l;i <= r;i++)
	{
		while(top1 && s[mx[top1]] <= s[i])
			top1--;
		while(top2 && s[mn[top2]] >= s[i])
			top2--;
		for(int j = 1;j <= top1;j++)
			(kk[i - mx[j]] < s[mx[j]] - s[i]) && (kk[i - mx[j]] = s[mx[j]] - s[i]);
		for(int j = 1;j <= top2;j++)
			(kk[i - mn[j]] < s[i] - s[mn[j]]) && (kk[i - mn[j]] = s[i] - s[mn[j]]);
		mx[++top1] = i;
		mn[++top2] = i;
	}
	for(long long i = 1;i <= r - l + 1;i++) if(kk[i])
		res = (cmp(res,{SQR(kk[i]),i}) ? res : make_pair(SQR(kk[i]),i));
	long long g = __gcd(res.first,res.second);
	cout << res.first / g << " " << res.second / g << "\n";
}
typedef struct{
	int l,r,id;
}AD;
bool st(AD A,AD B)
{
	return A.r < B.r;
}
AD q[300011];
pair<long long,long long> ans[300011];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	cin >> n;
	for(int i = 1;i <= n;i++)
		t[i] = {0,1};
	for(int i = 1;i <= n;i++)
		cin >> a[i],s[i] = s[i - 1] + a[i];
	cin >> m;
	if(m == 1)
	{
		Solve();
		return 0;
	}
	for(int i = 1;i <= n;i++)
		niu_niu[i] = {0,1};
	mx[top1 = 1] = mn[top2 = 1] = 0;
	for(int i = 1;i <= n;i++)
	{
		while(top1 && s[mx[top1]] <= s[i])
			top1--;
		while(top2 && s[mn[top2]] >= s[i])
			top2--;
		for(int j = 1;j <= top1;j++)
		{
			pair<long long,long long> w = QR(i,mx[j]);
			if(cmp(w,niu_niu[mx[j] + 1]))
				niu_niu[mx[j] + 1] = w,v[i].push_back({mx[j] + 1,w});
		}
		for(int j = 1;j <= top2;j++)
		{
			pair<long long,long long> w = QR(i,mn[j]);
			if(cmp(w,niu_niu[mn[j] + 1]))
				niu_niu[mn[j] + 1] = w,v[i].push_back({mn[j] + 1,w});
		}
		mx[++top1] = i;
		mn[++top2] = i;
	}
	for(int i = 1;i <= m;i++)
		cin >> q[i].l >> q[i].r,q[i].id = i;
	sort(q + 1,q + m + 1,st);
	for(int i = 1,j = 0;i <= m;i++)
	{
		while(j < q[i].r)
		{
			j++;
			for(auto x:v[j])
			{
				int l = x.first;
				auto w = x.second;
				add(l,w);
			}
		}
		ans[q[i].id] = ask(q[i].l);
	}
	for(int i = 1;i <= m;i++)
	{
		long long g = __gcd(ans[i].first,ans[i].second);
		cout << ans[i].first / g << " " << ans[i].second / g << "\n";
	}
	return 0;
}
